"""
演示带有时间线的柱状图开发
"""

from pyecharts.charts import Bar, Timeline
from pyecharts.globals import ThemeType
from pyecharts.options import LabelOpts

bar1 = Bar()
x_country = ["中国", "美国", "英国"]
y_gdp = [30, 20, 10]
bar1.add_xaxis(x_country)
bar1.add_yaxis("GDP", y_gdp, label_opts = LabelOpts(position="right"))
bar1.reversal_axis()

bar2 = Bar()
x_country = ["中国", "美国", "英国"]
y_gdp = [60, 40, 30]
bar2.add_xaxis(x_country)
bar2.add_yaxis("GDP", y_gdp, label_opts = LabelOpts(position="right"))
bar2.reversal_axis()

bar3 = Bar()
x_country = ["中国", "美国", "英国"]
y_gdp = [100, 70, 50]
bar3.add_xaxis(x_country)
bar3.add_yaxis("GDP", y_gdp, label_opts = LabelOpts(position="right"))
bar3.reversal_axis()

# 构建时间线对象
timeline = Timeline({"theme": ThemeType.LIGHT}) # 主题设置
# 在时间线内添加柱状图对象
timeline.add(bar1, "点1")
timeline.add(bar2, "点2")
timeline.add(bar3, "点3")
# 自动播放设置
timeline.add_schema(
    play_interval=500,
    is_timeline_show=True,
    is_auto_play=True,
    is_loop_play=True
)

# 绘图
timeline.render("基础时间线柱状图.html")